home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / MAKEAPP.SPK / !MakeApp2 / CLIapp / b2a_src (.txt) next >
RISC OS BBC BASIC V Source  |  1995-02-19  |  6KB  |  197 lines

  1.  This application is FreeWare. (c) 1995 Dick Alstein
  2. $;" at line ";
  3. loadprologue
  4. codesize%=&2000
  5.  armcode% codesize%
  6. leafname$="bas2app"
  7. 2help$="Syntax: "+leafname$+" infile [outfile]"
  8.     -fname$="<MakeApp2$Dir>.CLIapp."+leafname$
  9. assemble
  10.  "OS_File",10,fname$,&FF8,,code_start,code_end
  11. loadprologue
  12.  fn$,f%
  13. !fn$="<MakeApp2$Dir>.Prologue"
  14.  "OS_File",17,fn$ 
  15.  ,,,,prologuesize%
  16.  prologue% prologuesize%
  17.  "OS_GBPB",4,f%,prologue%,prologuesize%
  18.  set all line nunmbers in prologue to 0
  19.  prologue%?i%<>&FF
  20. 3  prologue%?i%=0       : 
  21.  set line nunber to 0
  22.   prologue%?(i%+1)=0
  23. 2  i%+=prologue%?(i%+2) : 
  24.  on to the next line
  25. 9prologuesize%=i%-1 : 
  26.  omit the terminating &0D + &FF
  27. assemble
  28. !    LR=14
  29. "    PC=15
  30. dblquote$=
  31. argbuffersize%=512
  32.  pass%=8 
  33.   P%=armcode%
  34.   L%=armcode%+codesize%
  35.   [ OPT pass%
  36. .code_start
  37.   B       conversion_start
  38. .argbuffer
  39. dim(argbuffersize%)
  40. .inputtype
  41.   EQUD    &FFB
  42. .outputtype
  43.   EQUD    &FF8  
  44. .commandsyntax
  45. 3-  EQUS    "Program,Help/S,Infile,Outfile"
  46.   EQUS    
  47.   ALIGN
  48. .helpstring
  49.   EQUS    help$
  50.   EQUS    
  51.   ALIGN
  52. .err_wrongtype
  53.   EQUD    0
  54. </  EQUS    "Input file must be a Basic file"
  55.   EQUS    
  56.   ALIGN
  57. .conversion_start
  58. A5  ; --- This is the part that does the conversion
  59. C.  ; 1. read the name of infile and outfile
  60.   SWI     "OS_GetEnv"
  61. F@  MOV     R1,R0              ; pointer to command line in R1
  62.   ADR     R0,commandsyntax
  63.   ADR     R2,argbuffer
  64. I   MOV     R3,#argbuffersize%
  65.   SWI     "OS_ReadArgs"
  66. K;  LDR     R0,[R2,#4]         ; check for "-Help" switch
  67.   TEQ     R0,#0
  68.   BNE     printhelp
  69. ND  LDR     R6,[R2,#8]         ; keep pointer to infile name in R6
  70.   TEQ     R6,#0
  71.   BEQ     printhelp
  72. QE  LDR     R7,[R2,#12]        ; keep pointer to outfile name in R7
  73.   TEQ     R7,#0
  74. Q   R7,R6              ; if no outfile name given then same as infile
  75. UB  ; 2. check filetype of infile and calculate size of outfile 
  76.   MOV     R0,#17
  77.   MOV     R1,R6
  78. Y!  SWI     "OS_File"          
  79.   MOV     R2,R2,LSL #12
  80.   LDR     R1,inputtype
  81.   CMP     R1,R2,LSR #20
  82.   ADR     R0,err_wrongtype
  83. ^   SWINE   "OS_GenerateError"
  84. _L  ADD     R8,R4,#prologuesize%  ; outputsize = infilesize + prologuesize
  85. a%  ; 3. fill in 'blanks' of prefix
  86.   STR     R8,program_size
  87.   LDR     R3,program_end
  88.   ADD     R3,R3,R8
  89.   STR     R3,program_end
  90.   LDR     R3,program_dest
  91.   ADD     R3,R3,R8
  92.   STR     R3,program_dest
  93.   ADD     R0,R8,#&9000
  94. k   ADR     R1,cmdline_endaddr
  95.   MOV     R2,#9
  96.   SWI     "OS_ConvertHex8"
  97. o'  ; 4. load input file after prefix
  98.   MOV     R0,#16
  99.   MOV     R1,R6
  100.   ADR     R2,prologue_end
  101.   MOV     R3,#0
  102.   SWI     "OS_File"
  103. w&  ; 5. write result to output file
  104.   MOV     R0,#10
  105.   MOV     R1,R7
  106.   LDR     R2,outputtype
  107. |!  ADR     R4,outputcode_start
  108. }6  ADD     R5,R4,#(prologue_start-outputcode_start)
  109.   ADD     R5,R5,R8
  110.   SWI     "OS_File"
  111.   ; 6. ready
  112.   SWI     "OS_Exit"
  113. .printhelp
  114.   ADR     R0,helpstring
  115.   SWI     "OS_Write0"
  116.   SWI     "OS_NewLine"
  117.   SWI     "OS_Exit"
  118. .outputcode_start
  119. K  ; --- This is the prefix that is prepended to the given Basic program
  120. &  ; 1. copy Basic program to &9000
  121.   LDR     R1,program_size
  122.   LDR     R2,program_end
  123.   LDR     R3,program_dest
  124. .copyabyte
  125.   LDRB    R0,[R2],#-1
  126.   STRB    R0,[R3],#-1
  127.   SUBS    R1,R1,#1
  128.   BNE     copyabyte
  129. &  ; 2a. construct new command line
  130. G  SWI     "OS_GetEnv"        ; get pointer to original command line
  131.    ADR     R2,newcmdline_rest
  132. O.copyachar                   ; copy first part (=name of the Absolute file)
  133.   LDRB    R1,[R0],#1
  134. 3  TEQ     R1,#0              ; stop if at zero 
  135. 1  TEQNE   R1,#
  136. (" ")       ; or if at a space
  137.   STRNEB  R1,[R2],#1
  138.   BNE     copyachar
  139. D  MOV     R3,#
  140. (dblquote$) ; file name goes between doublequotes
  141.   STRB    R3,[R2],#1
  142. B  MOV     R3,#
  143. (" ")       ; and is always followed by a space
  144.   STRB    R3,[R2],#1
  145. M  TEQ     R1,#0              ; if at zero then skip back to read it again
  146. !  SUBEQ   R0,R0,#1           
  147. Q.copytailchar                ; copy rest of command line (=arguments, if any)
  148.   LDRB    R1,[R0],#1
  149.   STRB    R1,[R2],#1
  150.   TEQ     R1,#0
  151.   BNE     copytailchar
  152. /  ; 2b. create environment variable from it
  153.   ADR     R0,varname
  154.   ADR     R1,newcmdline
  155. O  SUB     R2,R2,R1           ; length of string, including terminating zero
  156.   MOV     R3,#0
  157. A  MOV     R4,#4              ; variable type = literal string
  158.   SWI     "OS_SetVarVal"
  159.   ; 3. enter Basic
  160.   ADR     R0,cmdline
  161.   SWI     "OS_CLI"
  162. I  ; --- The following 4 data fields are filled in when bas2app is run
  163. .program_size
  164. F  EQUD    0                                  ; set to (outputsize)
  165. .program_end
  166. J  EQUD    &8000+(prologue_start-outputcode_start)-1 ; add (outputsize)
  167. .program_dest
  168. C  EQUD    &9000-1                            ; add (outputsize)
  169. .cmdline
  170. &  EQUS    "Basic -quit @00009000,"
  171. .cmdline_endaddr
  172. L  EQUS    "00000000"                         ; insert (&9000+outputsize)
  173.   EQUS    
  174. .varname
  175.   EQUS    "MakeApp2$CLI"
  176.   EQUS    
  177. .newcmdline
  178. &  EQUS    "Basic -quit "+dblquote$
  179. I  ; the rest is filled in after(!!) the Basic program has been moved,
  180. ,  ; otherwise it overwrites the prologue
  181. .newcmdline_rest     
  182. .prologue_start
  183. dim(prologuesize%) ; prologue contents to be filled in after assembling
  184. .prologue_end
  185. 0  ; --- The original Basic program goes here
  186. .code_end
  187.  pass%
  188.  put the prologue contents into place
  189.  i%=0 
  190.  prologuesize%-1
  191. # prologue_start?i%=prologue%?i%
  192. dim(size%)
  193.  i%=1 
  194.  size%
  195.   [ OPT pass%
  196.   EQUB    0
  197.